/*
 * Copyright (c) 2011-2012, Two Trolls Entertainment
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   * Neither the name of the Rhenium nor the
 *     names of its contributors may be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Two Trolls Entertainment BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef H_ENTITY
#define H_ENTITY

#include <vector>

#include "utils.h"
#include "mathhelper.h"


class Entity
{
    protected:
        Vec2F XY;
        GLuint texture;
        bool alive;

    public:
        Entity();
        Entity(Vec2F);
        Entity(Vec2F, const char *image_file_path);
        void render();
        virtual void tick(int)=0;
        bool isAlive();
        void kill();
        float getX();
        float getY();
};

class EntityPlayer : public Entity
{
    private:
        bool firstFrame;
        int lastFlash;
        float speed;
        GLuint textures[2];

    public:
        Utils::InputHandler *inputHandler;

        EntityPlayer(Vec2F XY) : Entity(XY)
        {
            lastFlash = 0;
            firstFrame = true;
            speed = 0.45;
            inputHandler = NULL;

            Utils::FileManager::loadTextureFromPNG(&textures[0], "./res/img/ship/ship.png");
            Utils::FileManager::loadTextureFromPNG(&textures[1], "./res/img/ship/ship.png");
        }
        ~EntityPlayer();
        void tick(int);
        void render(int);
        void addInputHandler(int, int);
        void handleMovement(SDL_Event event);
};

class EntityEmitter : public Entity
{

};

class EntityNPC : public Entity
{

};

class EntityBullet : public Entity
{
    private:
        float speed, angle;
        Vec2F XY;

    public:
        EntityBullet(int x, int y)
        {
            Utils::FileManager::loadTextureFromPNG(&texture, "./res/img/bullet/bullet1.png");
            XY.setX(x);
            XY.setY(y);
            angle = 90.0f;
            speed = 0.90f;
        }

        void tick(int);
        void render();
};

class EntityManager
{
    private:
        std::vector<EntityBullet> bullets;

    public:
        void addBullet(EntityBullet);
        void tick(int);
        void render();
};

#endif
